package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.ArtType;
import cn.gjculture.shopping.api.entity.Artist;
import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.ArtistService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/artist")
public class ArtistController {

    @Autowired
    ArtistService artistService;


    @ApiOperation(value = "新增艺术家", notes = "新增艺术家")
    @ApiImplicitParam(name = "artist", value = "艺术家对象", required = true, dataType = "Object")
    @PostMapping
    public Return save(Artist artist) {
        Return ret = new Return();
        if(artistService.insert(artist)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @ApiOperation(value = "修改艺术家", notes = "修改艺术家")
    @ApiImplicitParam(name = "artist", value = "艺术家对象", required = true, dataType = "Object")
    @PutMapping
    public Return<Artist> update(Artist artist){
        Return<Artist> ret=new Return<>();
        if(artistService.update(artist)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @ApiOperation(value = "获取艺术家列表", notes = "获取艺术家列表")
    @GetMapping
    public Return<List<Artist>> query(PageInfo pageInfo) {
        Return<List<Artist>> ret = new Return<>();
        List<Artist> artists = artistService.query();
        ret.setData(artists);
        if(!CollectionUtils.isEmpty(artists)){
            ret.getCommon().setRet(true);
        }
        return ret;
    }



    @ApiOperation(value = "获取艺术家", notes = "获取艺术家")
    @ApiImplicitParam(name = "artistId", value = "艺术家ID", required = true, dataType = "String",paramType = "path")
    @GetMapping(value = "/{artistId}")
    public Return<Artist> queryById(@PathVariable(value = "artistId") String artistId) {
        Return<Artist> ret = new Return<>();
        Artist artist = artistService.queryById(artistId);
        ret.setData(artist);
        if(artist!=null){
            ret.getCommon().setRet(true);
        }
        return ret;
    }


    @ApiOperation(value = "删除艺术家", notes = "删除艺术家")
    @ApiImplicitParam(name = "artistId", value = "艺术家ID", required = true, dataType = "String",paramType = "path")
    @DeleteMapping(value = "/{artistId}")
    public Return<ArtType> delete(@PathVariable(value = "artistId") String artistId) {
        Return<ArtType> ret = new Return<>();
        if(artistService.delete(artistId,ret)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }


}
